/* ************发送AJAX查询已经登录的用户**************** */
function findLoginName() {
    //1.发送ajax
    $.ajax({
        url: "admin/findloginAdmin",
        type: "post",
        data: {},
        dataType: "JSON",
        success: function(data) {
            //得到名字，显示在页面上
            showName(data["loginAdmin"]);
            //获取到菜单
            console.log(data["menuList"]);
            var menuInfos = data["menuList"]; //查询到的菜单
            var tree = []; //整理好的数据
            var firstId = 0;
            menuLoad(menuInfos, tree, firstId);
            console.log('tree:' + tree);
            //把数据放在树上
            var mytree = $('#treeMenu').data('zui.tree');
            mytree.reload(tree);
            // $('#treeMenu').tree({
            //     animate: true,
            //     initialState: 'expand',
            //     data: tree
            // });
        },
        error: function(data) {
            layer.confirm("请联系管理员", {
                btn: ['确定'] //按钮
            });
        }
    });
}
//名字显示在页面上的函数
function showName(admin) {
    var msg = "欢迎你:";
    msg += admin.adminName;
    $('#LoginName').html(msg);
    $('#loginAdminId').html(admin.adminId);
}
//显示左侧菜单
function menuLoad(menuInfos, tree, pid) {
    for (var i = 0; i < menuInfos.length; i++) {
        var menu = menuInfos[i];
        if (menu.pmenuId == pid) {
            var node = {
                html: `<li><a href="page?p=${menu.menuUrl}" target="center-jframe"><i class="icon icon-th"></i>${menu.menuName}</a></li>`,
                children: []
            };
            tree.push(node);
            menuLoad(menuInfos, node.children, menu.menuId);
        }
    }
}
//显示菜单
findLoginName();
/* ******************注销时间**************** */
function logoutAjax() {
    //1.发送ajax 
    $.ajax({
        url: "admin/deleteLoginAdminSession",
        type: "post",
        data: {},
        dataType: "JSON",
        success: function(data) {
            if (data) {
                //登录成功
                layer.confirm("注销成功", {
                    btn: ['确定'] //按钮
                }, function() {
                    location.href = "page?p=Login&d=" + Math.random();
                });
            }
        }
    })
}
$('#logOut').click(function() {
    logoutAjax();
});